package com.like.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.like.hospitalworld.R;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

public class HelperExpandableAdapter extends BaseExpandableListAdapter {

    private Context mContext;

    public HelperExpandableAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getGroupCount() {
        return 5;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return 1;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        GroupViewHolder vh;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_drug_helper_group, parent, false);
            vh = new GroupViewHolder(convertView);
            convertView.setTag(vh);
        } else
            vh = (GroupViewHolder) convertView.getTag();
        if (isExpanded) {
            vh.sDivider.setVisibility(View.GONE);
            vh.sTitle.setTextColor(0xff2892cb);
            Glide.with(mContext.getApplicationContext()).load(R.drawable.reply_more).into(vh.sDropIcon);
        } else {
            vh.sDivider.setVisibility(View.VISIBLE);
            vh.sTitle.setTextColor(0xff666666);
            Glide.with(mContext.getApplicationContext()).load(R.drawable.grey_arrow_up).into(vh.sDropIcon);
        }
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ChildViewHolder vh;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_drug_helper_child, parent, false);
            vh = new ChildViewHolder(convertView);
            convertView.setTag(vh);
        } else
            vh = (ChildViewHolder) convertView.getTag();
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    public class GroupViewHolder {

        @ViewInject(R.id.title)
        public TextView sTitle;
        @ViewInject(R.id.group_divider)
        public View sDivider;
        @ViewInject(R.id.drop_icon)
        public ImageView sDropIcon;

        public GroupViewHolder(View convertView) {
            x.view().inject(this, convertView);
        }

    }

    public class ChildViewHolder {
        @ViewInject(R.id.content)
        private TextView mContent;

        public ChildViewHolder(View convertView) {
            x.view().inject(this, convertView);
        }
    }
}
